<?php
namespace Home\Controller;
use Think\Controller;
class ParentController extends Controller {
	public function _initialize(){
		if(!session('?username')){
			$this -> error('请先登录，谢谢！','/Home/Login/index');
		}
	}
    public function index(){
        //$this->display();
    }
    // 计算周期
    public function calculation($id=null){
        if($id != null){
            $plane = M('plane')->where("id='%d'",$id)->find();
        }else{
            $plane = M('plane')->order('id desc')->find();
        }
        $start_time = $plane['start_time']; //开始时间
        $days_num = $plane['days']; //天数
        $sum_dans = $plane['plane_count']; //总刷单数
        $conver_start = $plane['plane_conver_star']; //起始转化率
        $conver_end = $plane['plane_conver_end']; //结束转化率

        // 周期内每天日期
        $days = next_some_day($start_time,$days_num);
        // 周期内每天转化率
        $convers = per_day_conver($conver_start, $conver_end, $days_num);
        // 周期内每天刷单数
        $dans = per_day_shuadan($sum_dans, $days_num);
        // 周期内每天流量
        $flows = per_day_flow($dans, $convers);

        // 每一天的情况
        $every_day = every_day($days,$dans,$convers,$flows);
        for($i=0;$i<count($every_day);$i++){
            $data[$i]['plane_id'] = $plane['id'];
            $data[$i]['date'] = strtotime($every_day[$i]['date']);
            $data[$i]['plane_num'] = (int)$every_day[$i]['dan'];
            $data[$i]['real_num'] = 0;
            $data[$i]['num_contrast'] = $data[$i]['plane_num'] - $data[$i]['real_num'];
            $data[$i]['plane_conver'] = (float)$every_day[$i]['convers'];
            $data[$i]['real_conver'] = (float)0;
            $data[$i]['conver_contrast'] = (float)($data[$i]['plane_conver'] - $data[$i]['real_conver']);
            $data[$i]['description'] = '无';
            $data[$i]['flow_num'] = $every_day[$i]['flows'];
            $data[$i]['real_flow'] = 0;
        }
        
        return $data;
        
    }
}